﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class TAM04STD
    {

        public TAM04STD()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VAMSTAMM();
            this.DataContext = MV;
            InitializeComponent();
        }

        public override void SaveCommand(object sender, RoutedEventArgs e)
        {
            try
            {
                if (dwMaster == null)
                    return;
                TMV.UpdateAMSTAMM(dwMaster, 0);
                base.SaveCommand(sender, e);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            { 
                AMTYP = "";
                AMART = "";
                AMKST = "";
            }
            else
            {
                
                AMTYP = TMV.AMTYP;
                AMART = TMV.AMART;
                AMKST = TMV.AMKSTKRS + AMKST;
            }
        }
        public override void LOADBYAUF()
        {

            if (ORDERNUM.Length < 8)
                return;
            dwData = TMV.TBMain.NewRow();
            dwData["AMMANDANT"] = app.Mandant;
            dwData["AMNRKRS"] = "AND AMNRKRS= '" + ORDERNUM.Substring(0, 2) + "'";
            dwData["AMLFDNR"] = "AND AMLFDNR= '" + ORDERNUM.Substring(2, 4) + "'";
            dwData["AMPOS"] = "AND AMPOS= '" + ORDERNUM.Substring(6, 2) + "'";
            SResult = TMV.QAM03(dwData);
            MergeData(SResult, true);
            base.LOADBYAUF();
        }
        public override void OnEXAUFChg(string value)
        {
            TBMain.Clear();
            if (EXAUF.Length < 14)
                return;
            dwData = TMV.TBMain.NewRow(); 
            dwData["AMMANDANT"] = app.Mandant; 
            dwData["AMKSTKRS"] = " AND AMKSTKRS= '" + EXAUF.Substring(0, 2) + "'";
            dwData["AMKST"] =  "AND AMKST= '" + EXAUF.Substring(2, 4) + "'";
            dwData["AMTYP"] = " AND AMTYP= '" + EXAUF.Substring(6, 8) + "'";
            dwData["AMSTDVAR"] = "J";
            SResult = TMV.QAM04(dwData);
            MergeData(SResult, true);
            base.OnEXAUFChg(value);
        }
        
    }
}
